package com.douqu.game.core.entity.ext.data.boon;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.EntityObject;

public class FlashSaleRecord extends EntityObject {
    /**
     * 限时促销ID
     */
    public int id;
    /**
     * 是否开放
     */
    public boolean isOpen;
    /**
     * 是否完成
     */
    public boolean isFinish;
    /**
     * 剩余次数
     */
    public int times;
    /**
     * 限时促销结束时间
     */
    public long endTime;

    public FlashSaleRecord() {
    }

    /**
     * 初始化玩家数据时用
     *
     * @param id 限时活动ID
     */
    public FlashSaleRecord(int id) {
        this.id = id;
        this.isOpen = false;
        this.isFinish = false;
        this.times = 0;
        this.endTime = 0L;
    }

    public void open(int times, long endTime) {
        this.isOpen = true;
        this.isFinish = false;
        this.times = times;
        this.endTime = endTime;
    }

    public void next(int id) {
        this.id = id;
        this.isOpen = false;
        this.isFinish = false;
        this.times = 0;
        this.endTime = 0L;
    }

    public void clear() {
        this.isOpen = false;
        this.isFinish = false;
        this.times = 0;
        this.endTime = 0L;
    }

    public void finish() {
        this.isOpen = false;
        this.isFinish = true;
        this.times = 0;
        this.endTime = 0L;
    }

    public void writeTo(ByteBuffer buffer) {
        buffer.writeInt(id);
        buffer.writeBoolean(isOpen);
        buffer.writeBoolean(isFinish);
        buffer.writeInt(times);
        buffer.writeLong(endTime);
    }

    public void loadFrom(ByteBuffer buffer) {
        id = buffer.readInt();
        isOpen = buffer.readBoolean();
        isFinish = buffer.readBoolean();
        times = buffer.readInt();
        endTime = buffer.readLong();
    }
}
